import { defineConfig } from "vite";

//plugin
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import legacy from "@vitejs/plugin-legacy";
import UnoCSS from "unocss/vite";
import path from "node:path";
// import AutoImport from "unplugin-auto-import/vite";
// import Components from "unplugin-vue-components/vite";
// import { VantResolver } from "@vant/auto-import-resolver";

export default defineConfig({
  root: "",
  base: "",
  publicDir: "public",
  esbuild: {
    jsxFactory: "h",
    jsxFragment: "Fragment",
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
      vue: "vue/dist/vue.esm-bundler.js",
    },
    extensions: [".js", ".vue", ".jsx", ".json", ".ts", ".tsx"],
  },
  json: {
    stringify: true,
  },
  clearScreen: false,
  server: {
    port: 9999,
    host: "0.0.0.0",
    open: false,
  },
  build: {
    target: "es2015",
    outDir: "dist",
    assetsInlineLimit: 4096,
    minify: "terser",
    chunkSizeWarningLimit: 2048,
    sourcemap: false,
    cssCodeSplit: true,
    rollupOptions: {
      output: {
        chunkFileNames: "assets/[name]-[hash].js",
        entryFileNames: "assets/[name]-[hash].js",
        assetFileNames: "assets/[name]-[hash].[ext]",
      },
    },
    emptyOutDir: true,
  },
  plugins: [
    vue(),
    vueJsx(),
    // AutoImport({
    //   resolvers: [VantResolver()],
    // }),
    // Components({
    //   resolvers: [VantResolver()],
    // }),
    UnoCSS(),
    legacy({ targets: ["ie>=11", "chrome >= 58"] }),
  ],
});
